package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;

import com.atguigu.gmall.product.service.FileUploadService;
import com.google.j2objc.annotations.RetainedLocalRef;
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.rmi.ServerException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
 * ClassName: FileUploadController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-08-19 9:51
 * @Version 1.0
 */

@Api(tags = "文件上传")
@RestController
@RequestMapping("/admin/product")
@RefreshScope /// nacos配置文件如果有数据修改，可以让代码中的数据进行热部署
public class FileUploadController {


    /**
     * 文件上传
     *
     * @param file
     * @return
     */


    @Autowired
    private FileUploadService fileUploadService;

    // 文件上传时，方法参数必须是file
    @SneakyThrows
    @PostMapping("/fileUpload")

    public Result fileUpload(MultipartFile file) {
        return fileUploadService.uploadFile(file);
    }

    public static void main(String[] args) {
        String fileName = "at.guigu.jpg";
        System.out.println(fileName.lastIndexOf("."));
        System.out.println(fileName.substring(8));
    }
}
